/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package telaCadastros;

import managertelaCadastros.managerCadServicoFuncionario;

/**
 *
 * @author fumio
 */
public class CadServicoFuncionario extends javax.swing.JDialog {

    private static CadServicoFuncionario cadServicoFuncionario;
    private static managerCadServicoFuncionario managerCadServicoFuncionario;

    public static CadServicoFuncionario getInstance(managerCadServicoFuncionario mCadServicoFuncionario) {
        cadServicoFuncionario = new CadServicoFuncionario(null, true);
        cadServicoFuncionario.setTitle("Cadastro de Servico x Funcionário");
        managerCadServicoFuncionario = mCadServicoFuncionario;
        return cadServicoFuncionario;
    }
    
    public CadServicoFuncionario(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    private void LimpaTela(){
        edtCodServico.setText("");
        edtServico.setText("");
        edtPercComissao.setText("");
        edtTempoServico.setText("");
        edtValorServico.setText("");
        
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        edtCodFuncionario = new javax.swing.JTextField();
        btnPesquisaFuncionario = new javax.swing.JButton();
        edtFuncionario = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        edtCodServico = new javax.swing.JTextField();
        btnPesquisaServico = new javax.swing.JButton();
        edtServico = new javax.swing.JTextField();
        edtPercComissao = new javax.swing.JFormattedTextField();
        edtTempoServico = new javax.swing.JFormattedTextField();
        edtValorServico = new javax.swing.JFormattedTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        btnAdicionar = new javax.swing.JButton();
        btnCancelarServico = new javax.swing.JButton();
        btnRemover = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblServicoFuncionario = new javax.swing.JTable();
        btnSair = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createCompoundBorder(null, new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
        jPanel1.add(edtCodFuncionario, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 30, 70, -1));

        btnPesquisaFuncionario.setText("P");
        btnPesquisaFuncionario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPesquisaFuncionarioActionPerformed(evt);
            }
        });
        jPanel1.add(btnPesquisaFuncionario, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 30, 60, -1));
        jPanel1.add(edtFuncionario, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 30, 380, -1));

        jLabel1.setText("Funcionário:");
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, -1));

        jPanel2.setBorder(javax.swing.BorderFactory.createCompoundBorder(null, new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
        jPanel2.add(edtCodServico, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 30, 70, 30));

        btnPesquisaServico.setText("P");
        btnPesquisaServico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPesquisaServicoActionPerformed(evt);
            }
        });
        jPanel2.add(btnPesquisaServico, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 30, 60, 30));
        jPanel2.add(edtServico, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 30, 380, 30));
        jPanel2.add(edtPercComissao, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 90, 130, 30));
        jPanel2.add(edtTempoServico, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 90, 130, 30));
        jPanel2.add(edtValorServico, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 150, 130, 30));

        jLabel2.setText("Serviço:");
        jPanel2.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, 20));

        jLabel3.setText("% Comissão:");
        jPanel2.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 70, -1, 20));

        jLabel4.setText("Vlr. Serviço:");
        jPanel2.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 130, -1, 20));

        jLabel5.setText("Tempo Serv.:");
        jPanel2.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 70, -1, 20));

        btnAdicionar.setText("Adicionar");
        btnAdicionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAdicionarActionPerformed(evt);
            }
        });
        jPanel2.add(btnAdicionar, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 190, -1, 70));

        btnCancelarServico.setText("Cancelar");
        btnCancelarServico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarServicoActionPerformed(evt);
            }
        });
        jPanel2.add(btnCancelarServico, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 190, 80, 70));

        btnRemover.setText("Remover");
        btnRemover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoverActionPerformed(evt);
            }
        });
        jPanel2.add(btnRemover, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 190, 90, 70));

        tblServicoFuncionario.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tblServicoFuncionario);

        jPanel2.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 270, 560, 160));

        btnSair.setText("Sair");
        btnSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSairActionPerformed(evt);
            }
        });
        jPanel2.add(btnSair, new org.netbeans.lib.awtextra.AbsoluteConstraints(470, 190, 80, 70));

        jPanel1.add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 70, 560, 430));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 489, Short.MAX_VALUE)
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-570)/2, (screenSize.height-531)/2, 570, 531);
    }// </editor-fold>//GEN-END:initComponents

    private void btnPesquisaServicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPesquisaServicoActionPerformed
        // TODO add your handling code here:
        managerCadServicoFuncionario.carregaPesquisaServico();
    }//GEN-LAST:event_btnPesquisaServicoActionPerformed

    private void btnPesquisaFuncionarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPesquisaFuncionarioActionPerformed
        // TODO add your handling code here:
        managerCadServicoFuncionario.carregaPesquisaFuncionario();
        LimpaTela();
    }//GEN-LAST:event_btnPesquisaFuncionarioActionPerformed

    private void btnCancelarServicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarServicoActionPerformed
        // TODO add your handling code here:
        LimpaTela();
        edtCodFuncionario.setEnabled(true);
        edtFuncionario.setEnabled(true);
        btnPesquisaFuncionario.setEnabled(true);
        edtCodFuncionario.setText("");
        edtFuncionario.setText("");
        edtCodFuncionario.requestFocusInWindow();
    }//GEN-LAST:event_btnCancelarServicoActionPerformed

    private void btnAdicionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAdicionarActionPerformed
        // TODO add your handling code here:       
       if (managerCadServicoFuncionario.salvar()){
           LimpaTela();
       }
    }//GEN-LAST:event_btnAdicionarActionPerformed

    private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSairActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_btnSairActionPerformed

    private void btnRemoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoverActionPerformed
        // TODO add your handling code here:
        if (managerCadServicoFuncionario.remover()) {
            LimpaTela();
        }
  
    }//GEN-LAST:event_btnRemoverActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JButton btnAdicionar;
    public javax.swing.JButton btnCancelarServico;
    public javax.swing.JButton btnPesquisaFuncionario;
    public javax.swing.JButton btnPesquisaServico;
    public javax.swing.JButton btnRemover;
    public javax.swing.JButton btnSair;
    public javax.swing.JTextField edtCodFuncionario;
    public javax.swing.JTextField edtCodServico;
    public javax.swing.JTextField edtFuncionario;
    public javax.swing.JFormattedTextField edtPercComissao;
    public javax.swing.JTextField edtServico;
    public javax.swing.JFormattedTextField edtTempoServico;
    public javax.swing.JFormattedTextField edtValorServico;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    public javax.swing.JTable tblServicoFuncionario;
    // End of variables declaration//GEN-END:variables
}
